package 动态代理;

public class jingtai {
}
interface ClothFactory{
    void produceCloth();
}

//被代理类
class NikeClothFactory implements ClothFactory{
    @Override
    public void produceCloth() {
        System.out.println("NIKE生产了一批运动服");
    }
}

//被代理类2
class ADDSClothFactory implements ClothFactory{
    @Override
    public void produceCloth() {
        System.out.println("adds生产了一批运动服");
    }
}

//代理类
class ProxyClothFactory implements ClothFactory{
    private ClothFactory factory;
    public ProxyClothFactory(ClothFactory factory){
        this.factory = factory;
    }
    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一些准备工作");
        factory.produceCloth();
        System.out.println("代理工厂做一些结尾工作");
    }
}
class StaticProxyTest {
    public static void main(String[] args) {
        //创建被代理类
        NikeClothFactory nike = new NikeClothFactory();
        ADDSClothFactory adds = new ADDSClothFactory();
        //创建代理类
        ProxyClothFactory proxyClothFactory = new ProxyClothFactory(nike);
        //此处的nike传入体现了多态性
        proxyClothFactory.produceCloth();

        ProxyClothFactory proxyClothFactory1 = new ProxyClothFactory(adds);
        //传入adds被代理
        proxyClothFactory1.produceCloth();
    }
}